package bz.ziro.kanbe.controller.file;

import java.util.Date;
import java.util.logging.Logger;

import org.slim3.controller.Navigation;
import org.slim3.util.BeanUtil;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

import bz.ziro.kanbe.model.SiteFile;
import bz.ziro.kanbe.util.KeyFactory;

/**
 * ファイル追加コントローラー
 * @author Administrator
 */
public class AddController extends FileUploadController {

    @SuppressWarnings("unused")
    private static final Logger logger = Logger.getLogger(AddController.class.getName());

    @Override
    public Navigation runFileUpload() {

        SiteFile fileObj = new SiteFile();
        BeanUtil.copy(request, fileObj);
        //キーを作成
        Key fileKey = KeyFactory.allocateFileKey();
        fileObj.setKey(fileKey);

        //データを登録
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        //作成日を設定
        fileObj.setCreateDate(new Date());
        fileObj.setCreator(user);

        //ファイルデータの設定
        setFileData(fileObj);
        return null;
    }
}
